home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / msdos / animutil / fastgfx / fg303b / manuals.arj / USER17.DOC < prev    next >
Encoding:
Text File  |  1993-10-02  |  8.2 KB  |  214 lines

  1. Chapter 17
  2.  
  3.  
  4.  
  5.  
  6.  
  7. Miscellaneous Routines
  8.  
  9. 304   Fastgraph User's Guide
  10.  
  11.  
  12. Overview
  13.  
  14.      There are a few remaining Fastgraph routines that really don't fit into
  15. any of the categories discussed so far.  For this reason, they are described
  16. separately in this chapter.
  17.  
  18.  
  19. Determining Available Memory
  20.  
  21.      The fg_memavail routine returns the amount of free conventional memory
  22. (in bytes) available to DOS.  It returns the amount of memory as its function
  23. value, which is a 32-bit unsigned integer.  Fg_memavail has no arguments.
  24.  
  25.      Example 17-1 uses fg_memavail to show the effects of creating and
  26. releasing virtual pages.  When run in a video mode in which video pages 1 and
  27. 2 are physical pages, the amount of free memory remains the same because
  28. these pages use memory that is resident on the video adapter.  However, in
  29. modes where pages 1 and 2 are virtual pages, the amount of free memory
  30. decreases after each call to fg_allocate and returns to its original value
  31. after the calls to fg_freepage.  Note how the program requests and validates
  32. the video mode.
  33.  
  34.                                 Example 17-1.
  35.  
  36.        #include <fastgraf.h>
  37.        #include <stdio.h>
  38.        #include <stdlib.h>
  39.        void main(void);
  40.  
  41.        void main()
  42.        {
  43.           long original, mem0, mem1, mem2;
  44.           int  mode, old_mode;
  45.  
  46.           printf("Which video mode? ");
  47.           scanf("%d",&mode);
  48.  
  49.           if (fg_testmode(mode,0) == 0) {
  50.              printf("Your system does not support that video mode.\n");
  51.              exit(1);
  52.              }
  53.           if (fg_testmode(mode,3) == 0) {
  54.              printf("Your system does not have enough memory.\n");
  55.              exit(1);
  56.              }
  57.  
  58.           original = fg_memavail();
  59.           old_mode = fg_getmode();
  60.           fg_setmode(mode);
  61.           mem0 = fg_memavail();
  62.           fg_allocate(1);
  63.           mem1 = fg_memavail();
  64.           fg_allocate(2);
  65.           mem2 = fg_memavail();
  66.  
  67.           fg_freepage(1);
  68.                                      Chapter 17:  Miscellaneous Routines   305
  69.  
  70.           fg_freepage(2);
  71.           fg_setmode(old_mode);
  72.           fg_reset();
  73.  
  74.           printf("originally     = %ld\n",original);
  75.           printf("after setmode  = %ld\n",mem0);
  76.           printf("after 1st page = %ld\n",mem1);
  77.           printf("after 2nd page = %ld\n",mem2);
  78.           printf("at end         = %ld\n",memavail());
  79.        }
  80.  
  81.  
  82. Choosing the Video Memory Update Function
  83.  
  84.      In Chapter 12, we saw how to use the fg_setfunc routine to perform XOR
  85. animation in native EGA and VGA graphics modes (modes 13 to 18).  In these
  86. video modes, fg_setfunc controls the logical operation applied when the
  87. contents of video memory change.  The specific operation is defined by its
  88. argument, as shown below.
  89.  
  90.                      value of   logical
  91.                      argument  operation
  92.  
  93.                          0    replacement
  94.                          1        and
  95.                          2        or
  96.                          3   exclusive or
  97.  
  98. If your program does not use the fg_setfunc routine, replacement mode is
  99. always used.  That is, information written to video memory replaces whatever
  100. was there before.  Again, fg_setfunc is meaningful only in modes 13 to 18.
  101.  
  102.      Example 17-2 demonstrates the fg_setfunc routine.  The program is
  103. similar to example 6-11 which displays 200 random rectangles on the screen.
  104. However, example 17-2 displays the rectangles in XOR mode, which means the
  105. rectangle intersections will appear in different colors.
  106.  
  107.                                 Example 17-2.
  108.  
  109.             #include <fastgraf.h>
  110.             #include <stdio.h>
  111.             #include <stdlib.h>
  112.             void main(void);
  113.  
  114.             #define RECTANGLES 200
  115.             #define SWAP(a,b,temp) { temp = a; a = b; b = temp; }
  116.  
  117.             void main()
  118.             {
  119.                int i;
  120.                int minx, maxx, miny, maxy;
  121.                int old_mode;
  122.                int temp;
  123.                int xres, yres;
  124.  
  125.                if (fg_egacheck() == 0) {
  126.  
  127. 306   Fastgraph User's Guide
  128.  
  129.  
  130.                   printf("This program requires EGA or VGA.\n");
  131.                   exit(1);
  132.                   }
  133.  
  134.                old_mode = fg_getmode();
  135.                fg_setmode(fg_automode());
  136.                fg_setfunc(3);
  137.  
  138.                xres = fg_getmaxx() + 1;
  139.                yres = fg_getmaxy() + 1;
  140.  
  141.                for (i = 0; i < RECTANGLES; i++) {
  142.                   minx = rand() % xres;
  143.                   maxx = rand() % xres;
  144.                   miny = rand() % yres;
  145.                   maxy = rand() % yres;
  146.                   if (minx > maxx)
  147.                      SWAP(minx,maxx,temp);
  148.                   if (miny > maxy)
  149.                      SWAP(miny,maxy,temp);
  150.                   fg_setcolor(rand()%16);
  151.                   fg_rect(minx,maxx,miny,maxy);
  152.                   }
  153.  
  154.                fg_setmode(old_mode);
  155.                fg_reset();
  156.             }
  157.  
  158.  
  159.  
  160. Controlling Vertical Retrace Synchronization
  161.  
  162.      The vertical retrace is the brief period when the monitor's electron
  163. beam travels from the bottom of the screen back to the upper left corner to
  164. begin a new display refresh cycle.  Depending on the monitor, the vertical
  165. retrace typically occurs between 50 and 60 times per second.
  166.  
  167.      Certain graphics operations must be performed during a vertical retrace
  168. interval to avoid potential screen flickering or snow.  These include page
  169. flipping, panning, and reading or writing a block of video DAC registers or
  170. palettes.  By default, Fastgraph's routines that perform these operations
  171. automatically provide the necessary vertical retrace synchronization.  In
  172. most applications, these vertical retrace controls are completely sufficient.
  173. There are times, however, when you may wish to disable Fastgraph's vertical
  174. retrace checking and perform the vertical retrace synchronization at the
  175. application level.
  176.  
  177.      This is the purpose of Fastgraph's fg_waitvr routine.  To disable all
  178. internal vertical retrace synchronization within Fastgraph, call fg_waitvr
  179. with a zero argument.  If you want to re-enable it, pass a non-zero value to
  180. fg_waitvr (note that this is the default state).  The Fastgraph routines
  181. relevant to the vertical retrace are fg_getdacs, fg_makegif, fg_makepcx,
  182. fg_palettes, fg_pan, fg_setdacs, fg_setvpage, fg_showgif, and fg_showpcx.
  183. The vertical retrace is applicable to fg_makepcx and fg_showpcx in 16-color
  184. and 256-color graphics modes only.
  185.                                      Chapter 17:  Miscellaneous Routines   307
  186.  
  187.  
  188.      As an example of why you might want to do disable Fastgraph's vertical
  189. retrace controls, consider page flipping.  After fg_setvpage defines the
  190. display start address for the new visual page, it waits for a vertical
  191. retrace interval so the new starting address can take effect.  If fg_setvpage
  192. didn't do this, graphics displayed before the next vertical retrace would
  193. sometimes appear on the screen before the old visual page is completely
  194. removed.  Suppose, though, that immediately after the page flip you did some
  195. calculations or other work that didn't affect the video display.  If you
  196. disable Fastgraph's vertical retrace synchronization, you might achieve a
  197. faster frame rate because you can perform the post-page-flip calculations
  198. during a time when the system is normally waiting for the vertical retrace.
  199. Depending on the extent of these calculations, you may find that it's not
  200. even necessary to wait for the vertical retrace following a page flip.
  201.  
  202.  
  203. Summary of Miscellaneous Routines
  204.  
  205.      This section summarizes the functional descriptions of the Fastgraph
  206. routines presented in this chapter.  More detailed information about these
  207. routines, including their arguments and return values, may be found in the
  208. Fastgraph Reference Manual.
  209.  
  210.      FG_MEMAVAIL returns the amount of memory available to DOS.
  211.  
  212.      FG_SETFUNC specifies the logical operation (replacement, or, and,
  213. exclusive or) applied when video memory changes in the native EGA and VGA
  214. graphics modes.  This routine has no effect in other video modes.
  215.  
  216.      FG_WAITVR disables or enables vertical retrace synchronization within
  217. Fastgraph.
  218. 308   Fastgraph User's Guide
  219.